package com.visikard.asynctask;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.visikard.application.UIMessage;
import com.visikard.business.AccountBUS;
import com.visikard.response.BaseResponse;
import com.visikard.response.MerchantGetDashBoardInfoResponse;

public class MerchantGetDashBoardInfoTask extends BaseTask {
	public static final int POS_MERCHANT_ID = 0;
	public static final int POS_ID_KARDS = 1;

	public MerchantGetDashBoardInfoTask(Handler handler) {
		super(handler);
	}

	public MerchantGetDashBoardInfoTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	/*
	 * (non-Javadoc)
	 * @see android.os.AsyncTask#doInBackground(java.lang.Object[])
	 */
	@Override
	protected Object doBackgroundWork(Object... params) {
		long merchantId = (Long) params[POS_MERCHANT_ID];
		long idKards = (Long) params[POS_ID_KARDS];

		AccountBUS busObj = new AccountBUS();
		MerchantGetDashBoardInfoResponse response = busObj.merchantGetDashBoardInfo(merchantId, idKards);

		return response;
	}

	@Override
	protected boolean handleResult(Object result) {
		MerchantGetDashBoardInfoResponse response = (MerchantGetDashBoardInfoResponse) result;
		if (response != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					Message successMsg = new Message();
					successMsg.what = UIMessage.MSG_MERCHANT_GET_DASHBOARD_INFO_SUCCESS;
					Bundle data = new Bundle();
					successMsg.setData(data);
					data.putLong(UIMessage.KEY_TOTAL_AUDIENCES, response.getTotalAudiences());
					data.putLong(UIMessage.KEY_TOTAL_CAMPAIGNS, response.getTotalCampaigns());
					data.putLong(UIMessage.KEY_TOTAL_POINTS, response.getTotalPoints());
					data.putLong(UIMessage.KEY_TOTAL_COUPONS, response.getTotalCoupons());
					data.putLong(UIMessage.KEY_TOTAL_GIFTKARDS, response.getTotalGiftKards());
					mUIHandler.sendMessage(successMsg);
					return true;
			}
		}
		return false;
	}
}
